package com.nxy.cpfsfe.config;


import com.adtec.starring.util.SpringUtil;
import com.nxy.cpfsfe.cache.DbRefresh;
import com.nxy.cpfsfe.cache.DbToParmToCache;
import com.nxy.cpfsfe.cache.DbTpRefrshTblnmToCache;
import com.nxy.cpfsfe.mybatis.mapper.ToParmMapper;
import com.nxy.cpfsfe.mybatis.mapper.TpRefrshTblnmMapper;
import com.nxy.cpfsfe.mybatis.pojo.ToParm;
import com.nxy.cpfsfe.mybatis.pojo.TpRefrshTblnm;

import org.apache.ibatis.session.SqlSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

public class DbConfig {

	public static final Logger LOGGER = LoggerFactory.getLogger(DbConfig.class);

	public static void  init() throws Exception{

		LOGGER.info("数据库加载初始化.......");


		initToParm();
		initTpRefrshTblnm();
		LOGGER.info("数据库挂载成功");
		
		DbRefresh dbRefresh = new DbRefresh();
		dbRefresh.tmChkTask();

	}

	public static void initTpRefrshTblnm(){
		LOGGER.info("参数刷新控制表初始化.......");

		SqlSession mybatisSqlSession =(SqlSession) SpringUtil.getBean("mybatisSqlSession");
		TpRefrshTblnmMapper dao = mybatisSqlSession.getMapper(TpRefrshTblnmMapper.class);
		List<TpRefrshTblnm> tpRefrshTblnmList =dao.findAllTpRefrshTblnm();
		DbTpRefrshTblnmToCache.refreshTpRefrshTblnm(tpRefrshTblnmList);

	}

    public static void initToParm(){
        LOGGER.info("系统参数表初始化.......");

        SqlSession mybatisSqlSession =(SqlSession) SpringUtil.getBean("mybatisSqlSession");
        ToParmMapper dao = mybatisSqlSession.getMapper(ToParmMapper.class);
        List<ToParm> toParmList =dao.findAllToParm();
        DbToParmToCache.refreshToParmDao(toParmList);

    }




	





	


	
}
